using System;
using Randomize.Core.Generators;

namespace Randomize.Core.Descriptors
{
    public class CustomDescriptor<TGenerate> : GenerationDescriptor<TGenerate, ICustomDescriptor<TGenerate>>, ICustomDescriptor<TGenerate>
    {
        private Func<Random, IGenerator<TGenerate>> _createGenerator;

        public override IGenerator<TGenerate> CreateGenerator(Random random)
        {
            return _createGenerator == null ? 
                new DefaultGenerator<TGenerate>(random) {Pool = this.Pool} : 
                _createGenerator(random);
        }

        public ICustomDescriptor<TGenerate> WithGenerator(Func<Random, IGenerator<TGenerate>> createGenerator)
        {
            _createGenerator = createGenerator;
            return this;
        }
    }
}